package com.yh.hljapp.modules.adatper;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.yh.hljapp.R;
import com.yh.hljapp.common.StringUtils;
import com.yh.hljapp.gddb.gbmanager.BackMatManager;
import com.yh.hljapp.gddb.gbmanager.MatHeadManager;
import com.yh.hljapp.gddb.gdbean.BackMatBean;

import java.util.ArrayList;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * =========================
 * 版权所有，违法必究
 * 作者：john
 * <p>
 * 工程：FoodBarcode
 * <p>
 * 文件名：BackMatAdapter
 * <p>
 * 创建时间：2017.05.27.14:40
 * *****************************
 */
public class BackMatAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private Context mContext;
    private ArrayList<BackMatBean> workInfos;

    public BackMatAdapter(Context context, ArrayList<BackMatBean> checkedCKS, OnSaleAddAdapterListern listener) {
        this.mContext = context;
        this.workInfos = checkedCKS;
        this.listener = listener;
    }

    public ArrayList<BackMatBean> getBackList() {
        return workInfos;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_sale_out, parent,
                false);
        return new BackViewHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        BackMatBean backMatBean = workInfos.get(position);
        initDataView((BackViewHolder) holder, backMatBean, position);
    }

    public void initDataView(final BackViewHolder holder, final BackMatBean bean, final int position) {
        String value = MatHeadManager.getInstance(mContext).getHeadValue("发货仓库", "3");
        double v =0;

        BackMatBean tdcStockByID = BackMatManager.getInstance(mContext).getTDCStockByID(bean.getId());
        if (!StringUtils.isEmpty(tdcStockByID.getTDCStockName())) {
            holder.tvFhWare.setText(tdcStockByID.getTDCStockName());//发货仓库
        } else {
            holder.tvFhWare.setText(value);//发货仓库
        }

        holder.tvCcCode.setText(bean.getNumber());
        holder.tvSfNum.setText(bean.getCount());
        holder.tvGgModle.setText(bean.getModel());


        holder.tvCcName.setText(bean.getName());
        holder.llFhck.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (listener != null) {
                    listener.onFHCKClick(bean);
                }
            }
        });

    }

    private OnSaleAddAdapterListern listener;

    public interface OnSaleAddAdapterListern {
        void onFHCKClick(BackMatBean position);
        void onDwClick(BackMatBean position, TextView tvUnit);
    }

    @Override
    public int getItemCount() {
        return workInfos.size();
    }

    class BackViewHolder extends RecyclerView.ViewHolder {
        @InjectView(R.id.tv_cc_code)
        TextView tvCcCode;
        @InjectView(R.id.tv_cc_name)
        TextView tvCcName;
        @InjectView(R.id.tv_gg_modle)
        TextView tvGgModle;
        @InjectView(R.id.tv_unit)
        TextView tvUnit;
        @InjectView(R.id.tv_sf_num)
        EditText tvSfNum;

        @InjectView(R.id.tv_fh_ware)
        TextView tvFhWare;
        @InjectView(R.id.ll_fhck)
        LinearLayout llFhck;

        public BackViewHolder(View view) {
            super(view);
            ButterKnife.inject(this, view);
        }
    }
}
